cat <<EOF
Hello, This is StdEnv script.

Timezone: Asia/Shanghai
Keyboard: English(US)

Username    : catroll
Password    : catroll123
Display Name: Hu Ang
PC Name     :
EOF

function confirm () {
    read -p "Continue (y/n)? " choice
    case "$choice" in 
        y|Y ) return 1 ;;
        n|N ) return 0 ;;
        * ) return $(confirm) ;;
    esac
}

function ptitle () {
    top="**************************************************";
    bottom=$top;
    columns=${#top};
    title=$1;
    echo "\n$top";
    printf "*****%*s%*s*****" $(((($columns+${#title})/2)-5)) "$title" $(((($columns-${#title})/2)-5)) "";
    echo "\n$bottom\n\n";
}
ptitle ss

function step1 () {

    mkdir ~/Projects
    mkdir ~/Projects/Mine       # 个人项目
    mkdir ~/Projects/Company    # 工作
    mkdir ~/Projects/Forked     #
    mkdir ~/Projects/StdEnv     #
    mkdir ~/Projects/Web        # Web 相关
    mkdir ~/Projects/Study      #

    mkdir ~/Tools
    mkdir ~/Space
    mkdir ~/Temp

    mkdir ~/Documents/Books
    mkdir ~/Documents/Mine
}

echo "1. 创建目录"


echo ""
echo "**************************************************"
echo "*****          1. 卸载不需要的软件           *****"
echo "**************************************************"
echo ""

# 游戏：对对碰、扫雷、数独、AisleRoit接龙
sudo apt remove -y gnome-mahjongg gnome-mines gnome-sudoku aisleriot
# 茄子、扫描易
sudo apt remove -y cheese simple-scan
# LibreOffice
sudo apt purge -y "libreoffice*"
# Amazon 的推广
sudo apt remove -y ubuntu-web-launchers

echo ""
echo "**************************************************"
echo "*****              2. 系统更新               *****"
echo "**************************************************"
echo ""

# sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com EB3E94ADBE1229CF
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /tmp/microsoft.gpg
sudo install -o root -g root -m 644 /tmp/microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'

wget -qO - https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

wget -qO - https://typora.io/linux/public-key.asc | sudo apt-key add -
echo "deb https://typora.io/linux ./" | sudo tee /etc/apt/sources.list.d/typora.list

sudo cp /etc/apt/sources.list /etc/apt/sources.list.orig
source /etc/os-release
cat > /etc/apt/sources.list <<EOF
deb http://mirrors.cn99.com/ubuntu/ ${UBUNTU_CODENAME} main restricted universe multiverse
deb http://mirrors.cn99.com/ubuntu/ ${UBUNTU_CODENAME}-security main restricted universe multiverse
deb http://mirrors.cn99.com/ubuntu/ ${UBUNTU_CODENAME}-updates main restricted universe multiverse
deb http://mirrors.cn99.com/ubuntu/ ${UBUNTU_CODENAME}-backports main restricted universe multiverse
deb http://archive.canonical.com/ubuntu ${UBUNTU_CODENAME} partner
EOF

sudo apt update
sudo apt upgrade -y

echo ""
echo "**************************************************"
echo "*****            2. 安装必要软件             *****"
echo "**************************************************"
echo ""

sudo apt install -y gcc make perl
sudo apt install -y vim vim-scripts vim-doc ctags
sudo apt install -y git git-doc gitk git-flow git-svn gitg git-extras libgnome-keyring-dev
sudo apt install -y ssh sshpass
sudo apt install -y zsh
sudo apt install -y mysql-server mysql-client
sudo apt install -y nodejs npm
sudo apt install -y python python3 python-pip python3-pip python-dev python3-dev
sudo apt install -y nfs-kernel-server vagrant-libvirt gnome-boxes
sudo apt install -y thunderbird chromium-browser keepassx
sudo apt install -y synaptic apt-file mlocate gdebi
sudo apt install -y crudini chrome-gnome-shell
sudo apt install -y docker.io gnome-teeaks code typora ibus-rime librime-data-stroke
sudo apt install -y htop tree jq webp pwgen rsync glances meld curl wget dos2unix
sudo apt install -y sqlite sqlite3 sqlitebrowser
sudo apt install -y haproxy haproxy-doc privoxy proxychains

echo ""
echo "**************************************************"
echo "*****              2. 配置 SSH               *****"
echo "**************************************************"
echo ""

mkdir -p ~/.ssh/
ssh-keygen -t rsa -b 4096 -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub

cat > ~/.ssh/config <<EOF
Host *
    User root
    IdentityFile ~/.ssh/id_rsa
EOF

echo ""
echo "**************************************************"
echo "*****              2. 配置 git               *****"
echo "**************************************************"
echo ""

touch ~/.gitignore
git config --global user.name catroll
git config --global user.email ninedoors@126.com
git config --global core.editor vi
git config --global core.quotepath false  # 不转义路径中的非 ASCII 字符
git config --global core.filemode false
git config --global core.excludesfile ~/.gitignore
git config --global alias.st status
git config --global alias.ci commit
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.df diff
git config --global alias.cp cherry-pick
git config --global alias.unstage "reset HEAD --"
git config --global alias.last "log -1 HEAD"
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
git config --global push.default simple
git config --global diff.tool meld
git config --global log.date "format:%Y-%m-%d %H-%M-%S"

sudo apt install libgnome-keyring-dev
cd /usr/share/doc/git/contrib/credential/gnome-keyring
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring

echo ""
echo "**************************************************"
echo "*****             2. 配置 Shell              *****"
echo "**************************************************"
echo ""

echo '' >> ~/.bashrc
echo '# ls --time-style=...' >> ~/.bashrc
echo 'export TIME_STYLE="+%Y-%m-%d %H:%M:%S"' >> ~/.bashrc
echo '' >> ~/.bashrc


git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh --depth 1
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="candy"/' ~/.zshrc
# 还可以指定更新频率：UPDATE_ZSH_DAYS
sed -i '1i DISABLE_AUTO_UPDATE=true' ~/.zshrc

echo '' >> ~/.zshrc
echo '# ls --time-style=...' >> ~/.zshrc
echo 'export TIME_STYLE="+%Y-%m-%d %H:%M:%S"' >> ~/.zshrc
echo '' >> ~/.zshrc

echo ""
echo "**************************************************"
echo "*****              2. 配置 Node              *****"
echo "**************************************************"
echo ""

sudo npm upgrade -g npm --registry=https://registry.npm.taobao.org

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt install -y yarn

npm config set registry=https://registry.npm.taobao.org
yarn config set registry https://registry.npm.taobao.org

echo ""
echo "**************************************************"
echo "*****             2. 安装 VSCode             *****"
echo "**************************************************"
echo ""

sudo apt update
sudo apt install -y code